local jianyan = fk.CreateSkill {
  name = "mini__jianyan",
}

Fk:loadTranslationTable{
  ["mini__jianyan"] = "荐言",
  [":mini__jianyan"] = "出牌阶段限一次，你可以声明一种牌的类别或颜色，随机亮出牌堆中一张此类别或颜色的牌，然后你令一名男性角色获得此牌。",

  ["#mini__jianyan"] = "荐言：声明牌的类别或颜色，将一张符合条件的牌交给一名角色",
  ["#mini__jianyan-give"] = "荐言：将%arg交给一名角色",

  ["$mini__jianyan1"] = "开言纳谏，社稷之福。",
  ["$mini__jianyan2"] = "如此如此，敌军自破！",
}

jianyan:addEffect("active", {
  anim_type = "support",
  prompt = "#mini__jianyan",
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(jianyan.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  interaction = UI.ComboBox { choices = {"basic", "trick", "equip", "black", "red"} },
  on_use = function(self, room, effect)
    local player = effect.from
    local pattern = self.interaction.data
    if table.contains({"black", "red"}, pattern) then
      if pattern == "black" then
        pattern = ".|.|spade,club"
      else
        pattern = ".|.|heart,diamond"
      end
    else
      pattern = ".|.|.|.|.|" .. pattern
    end
    local cards = table.filter(room.draw_pile, function (id)
      return Fk:getCardById(id):matchPattern(pattern)
    end)
    if #cards == 0 then return end
    cards = table.random(cards, 1)
    room:turnOverCardsFromDrawPile(player, cards, jianyan.name)
    local targets = table.filter(room.alive_players, function(p)
      return p:isMale()
    end)
    if #targets > 0 then
      local to = room:askToChoosePlayers(player, {
        targets = targets,
        min_num = 1,
        max_num = 1,
        prompt = "#mini__jianyan-give:::" .. Fk:getCardById(cards[1]):toLogString(),
        skill_name = jianyan.name,
        cancelable = false,
      })[1]
      room:moveCardTo(cards, Card.PlayerHand, to, fk.ReasonJustMove, jianyan.name, nil, true, to)
    end

    room:cleanProcessingArea(cards, jianyan.name)
  end,
})

return jianyan
